

% Write about the hieratical tree to be able to use and reuse ontology and behaviors.

The agent system implemented is a prototype laying the foundation for an implementation of a complete system. When developing a prototype the design must be in focus, because the architectural baseline must be strong yet flexible and extendable. Therefore all communication between the agents must be conducted through the developed ontology, where the class AMessage is the central element. For an agent to send a message it must use the method constructMessage(Messageable agent, MessageType type). This method takes a parameter of the type Messageable. Therefore all agents in the systems must extend this class. Messageable is an abstract class which is a subclass of the Agent class in Jade.
For the agents to be able to use the ontology message handlers have been implemented in cyclic behaviours in all of them. The pseudo code below is a general description of how the message handlers are designed.


%input listing
\lstinputlisting[caption={(Pseudo Code) Handle Message Behaviour},label={unknown}]{Codes/HandleMessageBehavior.java}

%\begin{algorithm}{Select}{x,i}
%r \= size[left[x]] + 1 \\
%\begin{SWITCH}
%\item{i = r} \\
%\RETURN x
%\item{i < r} \\
%\RETURN
%\CALL{Select}(left[x], i)
%\item{\DEFAULT} \\
%\RETURN
%\CALL{Select}(right[x], i - r)
%\end{SWITCH}
%\end{algorithm}

%\begin{algorithm}{}{Pseudo Code}
%  class HandleMessagesBehaviour extends CyclicBehaviour \\
%  ACLMessage acl \= next message in message queue \\
%  \begin{IF}{message found}
%    message \= content of ACLMessage;
%	\begin{SWITCH}
%    \item{message sender} \\
%      \begin{IF}{sender is one of the agents to communicate with}
%        \begin{SWITCH}
%          \item{ACLMessage performatives} \\
%          \begin{IF}{performative match is found}
%						retrieve information to use \\
%						construct reply with constructMessage(..) if needed \\
%						send reply if constructed \\
%          \end{IF}
%        \end{SWITCH}
%      \end{IF}
%    \end{SWITCH}
%  \end{IF}
%\end{algorithm}

%input listing

As written the above is a common structure used in the agent system. In \sectionref{analysis}  an overview of the agents to be used in the complete SmartOffice system was found. \figureref{agents-figure-classdiagram} shows a class diagram containing the agents developed and their relationships in the prototype. Because of the space needed to show the message handling inner classes, they are left out of the class diagram.

\begin{figure}[H]
  \begin{center}
    \includegraphics[trim=0mm 0mm 0mm 0mm, clip, scale=.33]{Images/Design/Classdiagram.jpg}
    \caption{Ontology class diagram}
    \label{agents-figure-classdiagram}
  \end{center}
\end{figure} 